DATA1 SEGMENT
MAXLEN  DB  10
        DB  ?
STR1    DB  20   DUP(0), '$'
DIGIT   DW  3039H
LETTER  DW  617AH
BOOL    DB  0H
EXIST   DB  0AH, 0DH, '$'
NONE    DB  '?$'
DATA1 ENDS

STACK1 SEGMENT STACK
    DB  40H DUP(0)
STACK1 ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA1, SS:STACK1
BEGIN:
    MOV AX, DATA1
    MOV DS, AX
    LEA DX, MAXLEN
    MOV AH, 0AH
    INT 21H
    MOV DI, OFFSET  MAXLEN
    MOV DX, OFFSET  LETTER
    MOV AX, OFFSET  DIGIT
    CALL    FUNC1
    CALL    FUNC2
    LEA DX, STR1
    MOV AH, 09H
    INT 21H
    TEST    BOOL, 0FFH
    JNZ HA
    LEA DX, NONE
    MOV AH, 09H
    INT 21H
HA: MOV AH, 4CH
    INT 21H

FUNC1   PROC
        PUSHF
        MOV CX, DI
        INC CX
        MOV SI, CX
        INC SI
        JMP LOOPEND
LOP:    CMP DH, BYTE PTR [SI]
        JAE L3
L1:     CMP AL, BYTE PTR [SI]
        JBE LOOPEND
L2:     CMP AH, BYTE PTR [SI]
        JA  LOOPEND
        MOV BYTE PTR [SI], 0
L3:     CMP DL, BYTE PTR [SI]
        JBE LOOPEND
        AND BYTE PTR [SI], 0DFH
LOOPEND:INC SI
        LOOP    LOP
        POPF
        RET
FUNC1   ENDP

FUNC2   PROC
        PUSHF
        MOV CX, DI
        INC CX
        MOV SI, CX
        INC SI
LOP2:   TEST BYTE PTR [SI], 0FFH
        JNZ LOPEND
        INC SI
        JMP LO
LOPEND: MOV BOOL, 0FFH
        JMP SUC
LO:     LOOP    LOP2
SUC:    POPF
        RET
FUNC2   ENDP

CODE ENDS
    END BEGIN
